package com.bell.atensettings.widgets;

import com.bell.atensettings.R;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

public class RecoveryAlertDialog extends Dialog
{

    public RecoveryAlertDialog(Context context)
    {
        super(context);
    }

    public RecoveryAlertDialog(Context context, int param)
    {
        super(context, param);
    }

    public static class Builder
    {
        private View contentView;
        private Context context;
        private DialogInterface.OnClickListener negativeButtonClickListener;
        private DialogInterface.OnClickListener positiveButtonClickListener;
        private String title;

        public Builder(Context context)
        {
            this.context = context;
        }

        public RecoveryAlertDialog create()
        {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService("layout_inflater");
            final RecoveryAlertDialog alertDialog = new RecoveryAlertDialog(context, R.style.dialog);
            View view = inflater.inflate(R.layout.recovery_dialog, null);

            alertDialog.addContentView(view, new ViewGroup.LayoutParams(-1, -2));
            if (positiveButtonClickListener != null)
            {
                ((ImageButton) view.findViewById(R.id.ibt_dialog_positive))
                        .setOnClickListener(new View.OnClickListener()
                        {
                            public void onClick(View paramView)
                            {
                                positiveButtonClickListener.onClick(alertDialog, BUTTON_POSITIVE);
                            }
                        });
            }
            else
            {
                view.findViewById(R.id.ibt_dialog_positive).setVisibility(View.GONE);
            }

            if (negativeButtonClickListener != null)
            {
                ((ImageButton) view.findViewById(R.id.ibt_dialog_native)).setOnClickListener(new View.OnClickListener()
                {
                    public void onClick(View paramView)
                    {
                        negativeButtonClickListener.onClick(alertDialog, BUTTON_NEGATIVE);
                    }
                });
            }
            else
            {
                view.findViewById(R.id.ibt_dialog_native).setVisibility(View.GONE);
            }
            
            alertDialog.setContentView(view);
            return alertDialog;
        }

        public Builder setContentView(View view)
        {
            contentView = view;
            return this;
        }

        public Builder setNegativeButton(DialogInterface.OnClickListener listener)
        {
            negativeButtonClickListener = listener;
            return this;
        }

        public Builder setPositiveButton(DialogInterface.OnClickListener listener)
        {
            positiveButtonClickListener = listener;
            return this;
        }

        public Builder setTitle(int resint)
        {
            title = ((String) context.getText(resint));
            return this;
        }

        public Builder setTitle(String text)
        {
            title = text;
            return this;
        }
    }
}
